import java.io.*;
import java.util.Properties;

public class IoTest implements Serializable{

    //读：输入 写：输出
    public static void t1() throws Exception{
        //创建字符输入缓冲流
        BufferedReader br = new BufferedReader(new FileReader("E:\\w.txt"));
        String str = null;
        //判断下一个不为空
        while ((str = br.readLine()) != null){
            System.out.println(str);
        }
        br.close();
    }

    public static void t2() throws Exception{
        //创建字符输出缓冲流
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\w.txt",true));
        bw.write("哈哈哈哈哈");
        bw.newLine();   //换行
        bw.close();
    }

    public static void t3() throws Exception{
        //复制文件
        BufferedInputStream in = new BufferedInputStream(new FileInputStream("E:\\金坷垃原版广告_标清.flv"));
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("a.mp4"));
        byte[] chars = new byte[1024*10];
        int len = 0;
        while ((len = in.read(chars)) != -1){
            out.write(chars,0,len);
            out.flush();
        }
        out.close();
        in.close();
    }

    //缓冲字符转换流
    public static void t4() throws Exception{
        BufferedReader bf = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream("D:\\w.txt"),"gbk"));
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(
                        new FileOutputStream("D:\\a.txt",true),"gbk"));
        String str = null;
        while ((str = bf.readLine()) != null){
            bw.write(str);
            bw.newLine();
            bw.flush();
        }
        bw.close();
        bf.close();
    }

    //对象输出流
    public static void t5() throws Exception{
        //创建对象
        Person per = new Person("流",55,'男',"武汉","sdgddgdfg");
        //创建对象输出流
        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream("D:\\w.txt"));
        //输出对象
        out.writeObject(per);
        out.close();
    }

    public static void t6() throws Exception{
        //创建对象输入流
        ObjectInputStream in = new ObjectInputStream(
                new FileInputStream("D:\\w.txt"));
        Object o = in.readObject();
        if (o instanceof Person){
            Person p = (Person)o ;
            System.out.println(p);
        }

    }

    //打印流
    public static void t7() throws Exception{
        PrintWriter pw = new PrintWriter("a.txt");
        pw.println("sgfdfhgjj");
        pw.print(true);
        pw.close();
    }

    //配置文件
    public static void t8() throws Exception{
        Properties properties = new Properties();
        //通过properties加载配置文件
        properties.load(new FileReader("D:\\db.properties"));
        String className = properties.getProperty("className");
        System.out.println("className = " + className);
        String passWord = properties.getProperty("password");
        System.out.println("passWord = " + passWord);
    }
    public static void tip(){
        /**
         * I/O流总结
         *
         *基础流：字符流 / 字节流
         *      字符流：
         *          FileReader / FileWriter
         *          read(char[]) / write(String) / wirte(chars,0,len)
         *      字节流：
         *          FileInputStream / FileOutputStream
         *          read(byte[]) / write(XX.getBytes()) / write(bytes,0,len)
         *
         *缓冲流:
         *      缓冲字符流(字符流)
         *      BufferedReader(FileReader)
         *          readLine();
         *      BufferedWriter(FileWriter)
         *          write(str);
         *          newLine();
         *      缓冲字节流(字节流)
         *      BufferedInputStream(FileInputStream)
         *          read(byte[])
         *      BufferedOutputStream(FileOutputStream)
         *          write(XX.getBytes()) / write(bytes,0,len)
         *
         *缓冲&转换流:
         *      缓冲字符流(转换流(字节流))
         *      BufferedReader(InputStreamReader)
         */
    }
    public static void main(String[] args) throws Exception {
        t2();
    }
}
